<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:replace="common :: header"/>
<body>
<div class="page">
    <div class="card">
        <div class="card-body">
            <table id="table" lay-filter="table"></table>
        </div>
    </div>
</div>
<script type="text/html" id="toolbar">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>
        <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>
        <button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>
    </div>
</script>

<script type="text/html" id="rowbar">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script th:inline="javascript">
    var datas = [[${@dict.getType('sys_msg_type')}]];

    layui.use('table')
    var table = layui.table;

    table.render({
        elem: '#table',
        url:'/system/msg/list',
        where:  {field:'msgType', order:'desc'},
        height: 'full-70',
        toolbar: '#toolbar',
        page: true,
        limit: 20,
        limits: [10,20,50,100],
        loading: true,
        cols:[ [
            {field: 'ck', checkbox: true },
            {field: 'content', title: '消息内容', width: 500},
            {field: 'msgType', title: '消息类型', align:'center', sort: true},
            {field: 'createTime',title: '发送时间',align:'center',sortable: true, width: 140}
        ] ]
    })

    //监听排序事件
    table.on('sort(table)', function(obj){
        table.reload('table', {
            where: {field: obj.field ,order: obj.type }
        });
    });


    $('#btnShowRead').checkbox({
        label:'只看未读',
        onChange:function (checked) {
            var params = checked ? {status: 1} : {};
            dm.search('table', params);
        }
    });

    function read() {
        dm.getRows('table', 'msgId', function (ids) {
            $.post('/system/msg/read',{ids: ids}, (res) => {
                dm.search('table');
                if(res.data<=0){
                    $('#msg_dot', window.parent.document).addClass('layui-hide');// 隐藏小圆点
                }
            },'json')
        })
    }
    function readAll() {
        dm.post('/system/msg/readAll', {}, function () {
            dm.search('table');
        })
    }

</script>
</body>
</html>
